<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class DBQueue {
            #items = {};
            #lowCount = 0;
            #count = 0;

            addFront(data) {
                if (this.#lowCount > 0) {
                    this.#lowCount--;
                    this.#items[this.#lowCount] = data;
                }
                else{
                    this.#count++;
                    for(let i = this.#count;i>0;i--){
                        this.#items[i] = this.#items[i-1];
                    }
                    this.#items[0] = data;
                }
            }

            addBack(data){
                this.#count++;
                this.#items[this.#count]=data;
            }

            peekFront(){
                if(this.isEmpty()){
                    return ;
                }

                return this.#items[this.#lowCount];
            }

            peekBack(){
                if(this.isEmpty()){
                    return ;
                }

                return this.#items[this.#count];
            }

            delFront(){
                if (this.isEmpty()) {
                    return;
                }
                let i = this.#items[this.#lowCount];
                delete this.#items[this.#lowCount];
                this.#lowCount++;
                return i;
            }

            delBack(){
                if (this.isEmpty()) {
                    return;
                }
                this.#count--;
                let i = this.#items[this.#count];
                delete this.#items[this.#count];
                return i;
            }


            isEmpty() {
                return this.size() == 0;
            }

            size() {
                return this.#count - this.#lowCount;
            }

            toString(){
                let str = '';
                for(let item in this.#items){
                    str+=`${this.#items[item]} `;
                }
                return str;
            }
        }

        let dbqueue = new DBQueue();

        
    </script>
</body>

</html>